package cn.yto.wdgj.wdgjgptdigitaltool.controller;

import cn.yto.response.BaseResponse;
import cn.yto.response.DataResult;
import cn.yto.wdgj.common.reponse.MutiResponse;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.request.GptCaseMatcherRequest;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.request.GptTasFallbackRequest;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.response.GptTasFallbackResponse;
import cn.yto.wdgj.wdgjgptdigitaltool.service.GptTaskDialogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/fallback")
@Api(value = "回归执行结果查询接口", tags = {"回归执行结果查询接口"})
public class GptTaskDialogController {

    @Autowired
    private GptTaskDialogService gptTaskDialogService;

    @RequestMapping(value = "/execute", method = RequestMethod.POST)
    @ApiOperation(value = "回归执行接口", httpMethod = "POST", notes = "回归执行接口")
    public DataResult<BaseResponse> execute(@RequestBody GptCaseMatcherRequest gptCaseMatcherRequest) {
        try {
            gptTaskDialogService.execute(gptCaseMatcherRequest);
            return DataResult.ok();
        } catch (Exception e) {
            log.error("/dialog", e);
            return DataResult.fail(e.getMessage());
        }
    }

    @RequestMapping(value = "/getPage", method = RequestMethod.POST)
    @ApiOperation(value = "回归结果查询接口", httpMethod = "POST", notes = "回归结果查询接口")
    public DataResult<MutiResponse<GptTasFallbackResponse>> getPage(@RequestBody GptTasFallbackRequest request) {
        try {
            return gptTaskDialogService.getPage(request);
        } catch (Exception e) {
            log.error("/dialog", e);
            return DataResult.fail(e.getMessage());
        }
    }

}
